namespace SmartSoft.Lists
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmTteEditor : FormListEditor
    {
        private IContainer components;
        private LabelControl lblLoai_Tte;
        private LabelControl lblLoai_Tte0;
        private LabelControl lblMa_Tte;
        private LabelControl lblNgay_TyGia;
        private LabelControl lblTen_Tte;
        private LabelControl lblTy_Gia;
        private TextOption txtLoai_Tte;
        private TextOption txtMa_Tte;
        private TextDate txtNgay_TyGia;
        private TextControl txtTen_Tte;
        private TextNumeric txtTy_Gia;

        public FormDmTteEditor()
        {
            this.InitializeComponent();
            this.txtMa_Tte.InputMask = AppInstance.Currencies;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormDmTteEditor));
            this.txtMa_Tte = new TextOption();
            this.lblMa_Tte = new LabelControl();
            this.txtTen_Tte = new TextControl();
            this.lblTen_Tte = new LabelControl();
            this.lblNgay_TyGia = new LabelControl();
            this.txtTy_Gia = new TextNumeric();
            this.lblTy_Gia = new LabelControl();
            this.txtLoai_Tte = new TextOption();
            this.lblLoai_Tte = new LabelControl();
            this.lblLoai_Tte0 = new LabelControl();
            this.txtNgay_TyGia = new TextDate();
            base.SuspendLayout();
            base.txtMa_Loai3.FirstFilter = "Type = ''";
            base.txtMa_Loai3.Location = new Point(0x18c, 0x74);
            base.txtMa_Loai3.Size = new Size(0x85, 20);
            base.txtMa_Loai3.TabIndex = 7;
            base.txtMa_Loai2.FirstFilter = "Type = ''";
            base.txtMa_Loai2.Location = new Point(0x103, 0x74);
            base.txtMa_Loai2.Size = new Size(0x86, 20);
            base.txtMa_Loai2.TabIndex = 6;
            base.txtMa_Loai1.FirstFilter = "Type = ''";
            base.txtMa_Loai1.Location = new Point(0x7b, 0x74);
            base.txtMa_Loai1.Size = new Size(0x85, 20);
            base.txtMa_Loai1.TabIndex = 5;
            base.lblPhan_Loai.Location = new Point(12, 0x77);
            this.txtMa_Tte.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Tte.CheckTextSearched = false;
            this.txtMa_Tte.DisabledForeColor = Color.Empty;
            this.txtMa_Tte.Font = new Font("Arial", 8.25f);
            this.txtMa_Tte.InputMask = "";
            this.txtMa_Tte.Location = new Point(0x7b, 0x1c);
            this.txtMa_Tte.MaxLength = 0x20;
            this.txtMa_Tte.Name = "txtMa_Tte";
            this.txtMa_Tte.OldValue = null;
            this.txtMa_Tte.Size = new Size(0x85, 20);
            this.txtMa_Tte.TabIndex = 0;
            this.txtMa_Tte.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Tte.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Tte.Value = null;//manager.GetObject("txtMa_Tte.Value");
            this.lblMa_Tte.AutoSize = true;
            this.lblMa_Tte.Font = new Font("Arial", 8.25f);
            this.lblMa_Tte.Location = new Point(12, 0x1f);
            this.lblMa_Tte.Name = "lblMa_Tte";
            this.lblMa_Tte.Size = new Size(0x35, 14);
            this.lblMa_Tte.TabIndex = 4;
            this.lblMa_Tte.Text = "Mã tiền tệ";
            this.txtTen_Tte.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Tte.CheckTextSearched = false;
            this.txtTen_Tte.DisabledForeColor = Color.Empty;
            this.txtTen_Tte.Font = new Font("Arial", 8.25f);
            this.txtTen_Tte.Location = new Point(0x7b, 50);
            this.txtTen_Tte.MaxLength = 0x80;
            this.txtTen_Tte.Name = "txtTen_Tte";
            this.txtTen_Tte.OldValue = null;
            this.txtTen_Tte.Size = new Size(0x196, 20);
            this.txtTen_Tte.TabIndex = 1;
            this.txtTen_Tte.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Tte.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTen_Tte.Value = null;//manager.GetObject("txtTen_Tte.Value");
            this.lblTen_Tte.AutoSize = true;
            this.lblTen_Tte.Font = new Font("Arial", 8.25f);
            this.lblTen_Tte.Location = new Point(12, 0x35);
            this.lblTen_Tte.Name = "lblTen_Tte";
            this.lblTen_Tte.Size = new Size(0x39, 14);
            this.lblTen_Tte.TabIndex = 4;
            this.lblTen_Tte.Text = "Tên tiền tệ";
            this.lblNgay_TyGia.AutoSize = true;
            this.lblNgay_TyGia.Font = new Font("Arial", 8.25f);
            this.lblNgay_TyGia.Location = new Point(12, 0x4b);
            this.lblNgay_TyGia.Name = "lblNgay_TyGia";
            this.lblNgay_TyGia.Size = new Size(0x3d, 14);
            this.lblNgay_TyGia.TabIndex = 4;
            this.lblNgay_TyGia.Text = "Ngày tỷ giá";
            this.txtTy_Gia.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTy_Gia.DisabledForeColor = Color.Empty;
            this.txtTy_Gia.Font = new Font("Arial", 8.25f);
            this.txtTy_Gia.ForeColor = Color.Black;
            this.txtTy_Gia.Location = new Point(0x7b, 0x5e);
            this.txtTy_Gia.MaxLength = 0x80;
            this.txtTy_Gia.Name = "txtTy_Gia";
            int[] bits = new int[4];
            this.txtTy_Gia.NumericValue = new decimal(bits);
            this.txtTy_Gia.OldValue = null;
            this.txtTy_Gia.Size = new Size(0x85, 20);
            this.txtTy_Gia.TabIndex = 3;
            this.txtTy_Gia.TextAlign = HorizontalAlignment.Right;
            this.txtTy_Gia.UserTextNumericFormat = AppInstance.TextNumericFormat.ExchangeRate;
//            this.txtTy_Gia.Value = null;//manager.GetObject("txtTy_Gia.Value");
            this.lblTy_Gia.AutoSize = true;
            this.lblTy_Gia.Font = new Font("Arial", 8.25f);
            this.lblTy_Gia.Location = new Point(12, 0x61);
            this.lblTy_Gia.Name = "lblTy_Gia";
            this.lblTy_Gia.Size = new Size(0x24, 14);
            this.lblTy_Gia.TabIndex = 4;
            this.lblTy_Gia.Text = "Tỷ giá";
            this.txtLoai_Tte.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtLoai_Tte.CheckTextSearched = false;
            this.txtLoai_Tte.DisabledForeColor = Color.Empty;
            this.txtLoai_Tte.Font = new Font("Arial", 8.25f);
            this.txtLoai_Tte.InputMask = "0,1";
            this.txtLoai_Tte.Location = new Point(0x7b, 0x74);
            this.txtLoai_Tte.MaxLength = 0x80;
            this.txtLoai_Tte.Name = "txtLoai_Tte";
            this.txtLoai_Tte.OldValue = null;
            this.txtLoai_Tte.Size = new Size(0x17, 20);
            this.txtLoai_Tte.TabIndex = 4;
            this.txtLoai_Tte.Text = "0";
            this.txtLoai_Tte.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtLoai_Tte.UserTrimMode = AppInstance.TextControlTrimMode.All;
            this.txtLoai_Tte.Value = "0";
            this.lblLoai_Tte.AutoSize = true;
            this.lblLoai_Tte.Font = new Font("Arial", 8.25f);
            this.lblLoai_Tte.Location = new Point(12, 0x77);
            this.lblLoai_Tte.Name = "lblLoai_Tte";
            this.lblLoai_Tte.Size = new Size(0x38, 14);
            this.lblLoai_Tte.TabIndex = 4;
            this.lblLoai_Tte.Text = "Loại tỷ giá";
            this.lblLoai_Tte0.AutoSize = true;
            this.lblLoai_Tte0.Font = new Font("Arial", 8.25f);
            this.lblLoai_Tte0.ForeColor = Color.Blue;
            this.lblLoai_Tte0.Location = new Point(0x98, 0x77);
            this.lblLoai_Tte0.Name = "lblLoai_Tte0";
            this.lblLoai_Tte0.Size = new Size(0x4f, 14);
            this.lblLoai_Tte0.TabIndex = 4;
            this.lblLoai_Tte0.Text = "0-Nh\x00e2n, 1-Chia";
            this.txtNgay_TyGia.Font = new Font("Arial", 8.25f);
            this.txtNgay_TyGia.Location = new Point(0x7b, 0x48);
            this.txtNgay_TyGia.Name = "txtNgay_TyGia";
            this.txtNgay_TyGia.OldValue = null;
            this.txtNgay_TyGia.Size = new Size(0x85, 20);
            this.txtNgay_TyGia.TabIndex = 2;
            base.AddTitleText = "Thêm mới tỷ giá hạch toán";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x222, 150);
            base.Controls.Add(this.txtNgay_TyGia);
            base.Controls.Add(this.lblLoai_Tte0);
            base.Controls.Add(this.lblLoai_Tte);
            base.Controls.Add(this.lblTy_Gia);
            base.Controls.Add(this.lblNgay_TyGia);
            base.Controls.Add(this.lblTen_Tte);
            base.Controls.Add(this.lblMa_Tte);
            base.Controls.Add(this.txtLoai_Tte);
            base.Controls.Add(this.txtTy_Gia);
            base.Controls.Add(this.txtTen_Tte);
            base.Controls.Add(this.txtMa_Tte);
            base.EditTitleText = "Sửa tỷ giá hạch toán";
            base.Name = "FormDmTteEditor";
            base.ShowFreeFields = false;
            this.Text = "Thêm mới tỷ giá hạch toán";
            base.Controls.SetChildIndex(base.lblPhan_Loai, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai1, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai2, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai3, 0);
            base.Controls.SetChildIndex(this.txtMa_Tte, 0);
            base.Controls.SetChildIndex(this.txtTen_Tte, 0);
            base.Controls.SetChildIndex(this.txtTy_Gia, 0);
            base.Controls.SetChildIndex(this.txtLoai_Tte, 0);
            base.Controls.SetChildIndex(this.lblMa_Tte, 0);
            base.Controls.SetChildIndex(this.lblTen_Tte, 0);
            base.Controls.SetChildIndex(this.lblNgay_TyGia, 0);
            base.Controls.SetChildIndex(this.lblTy_Gia, 0);
            base.Controls.SetChildIndex(this.lblLoai_Tte, 0);
            base.Controls.SetChildIndex(this.lblLoai_Tte0, 0);
            base.Controls.SetChildIndex(this.txtNgay_TyGia, 0);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        public override bool OnSave()
        {
            DataRow localCurrentRow;
            if (string.IsNullOrEmpty(this.txtMa_Tte.Text))
            {
                MessageBox.Show("Chưa nhập mã tiền tệ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtTen_Tte.Text))
            {
                MessageBox.Show("Chưa nhập tên tiền tệ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (this.txtNgay_TyGia.Value == SDBNull.Value)
            {
                MessageBox.Show("Chưa nhập ngày tỷ giá!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.NewChecked)
            {
                localCurrentRow = base.LocalTable.NewRow();
            }
            else
            {
                localCurrentRow = base.LocalCurrentRow;
            }
            localCurrentRow["Ma_Tte"] = this.txtMa_Tte.Value;
            localCurrentRow["Ten_Tte"] = this.txtTen_Tte.Value;
            localCurrentRow["Ngay_TyGia"] = this.txtNgay_TyGia.Value;
            localCurrentRow["Ty_Gia"] = this.txtTy_Gia.Value;
            localCurrentRow["Loai_Tte"] = this.txtLoai_Tte.Value;
            DmTteDataAccess access = new DmTteDataAccess();
            if (base.ShowMessage(localCurrentRow, access.SaveRow(base.NewChecked, localCurrentRow)))
            {
                return false;
            }
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(localCurrentRow);
            }
            base.LocalCurrentRow = localCurrentRow;
            base.LocalTable.AcceptChanges();
            this.txtMa_Tte.Focus();
            return base.OnSave();
        }

        public override void OnShow()
        {
            this.txtMa_Tte.Value = base.LocalCurrentRow["Ma_Tte"];
            this.txtTen_Tte.Value = base.LocalCurrentRow["Ten_Tte"];
            this.txtNgay_TyGia.Value = base.LocalCurrentRow["Ngay_TyGia"];
            this.txtTy_Gia.Value = base.LocalCurrentRow["Ty_Gia"];
            this.txtLoai_Tte.Value = base.LocalCurrentRow["Loai_Tte"];
            base.OnShow();
        }
    }
}

